<?php
require_once("../../inc/global.php");
require_once("function.php");
adminislogin();
$MenuID=$_GET["MenuID"];
$id=$_GET["id"];
if(empty($MenuID)||!is_numeric($MenuID)||empty($id)||!is_numeric($id)){
//	$base->alert("参数不正确");
	YKT_error('参数不正确',$_SERVER['HTTP_REFERER']);
}
$html->includetop("","style=\"width:98%\"");
echo "\n<script type=\"text/javascript\" src=\"js/Calendar.js\"></script>\n当前位置：{$System->GetMenuSysField($System->GetMenuSysField($MenuID,2),1)} > {$System->GetMenuSysField($MenuID,1)} > 数据修改";
$MenuTableName=$System->GetTableName($MenuID);
//读取配置文件
$filepath="../{$MenuTableName}/{$MenuID}.tpl";
if(!file_exists($filepath)){
//	$base->alert("表单模版没有找到，请重新保存一下本栏目设置！！");
	if($_SESSION[ADMINSESSION][1]=='admin'){
		YKT_error('表单模版没有找到，请重新保存一下本栏目设置','/'.ADMINROOT.'/System/menusys/index.php');
	}else{
		YKT_error('表单模版没有找到，请重新保存一下本栏目设置',$_SERVER['HTTP_REFERER']);
	}
	
}
$fp=fopen($filepath,"r");
$mobantpl=fread($fp,filesize($filepath));
fclose($fp);
//读取数据库的数据
$MenuIDFieldName=$MenuTableName.$System->GetFormConfigMenuIDFieldID($MenuID);
$rowlist=$db->getoners("select * from {$MenuTableName} where {$MenuIDFieldName}={$MenuID} and {$MenuTableName}0={$id} limit 1");
//读取数据库配置
$getfromconfig=$System->GetMenuSysFormConfig($MenuID);
$getfromconfigarr=explode(",",$getfromconfig);
//替换
for($i=1;$i<count($getfromconfigarr);$i++){
	$fromlist=explode("|",$getfromconfigarr[$i]);
	if($fromlist[1]=="8"){
		$mobantpl=str_replace("{ykt:FileName_".$i."}",$MenuID,$mobantpl);
	}elseif($fromlist[1]=="10"){
		if(empty($rowlist[$i])){
			$timss = '';
		}else{
			$timss = date('Y-m-d',$rowlist[$i]);
		}
		$mobantpl=str_replace("{ykt:FileName_".$i."}",$timss,$mobantpl);
	}else{
		$mobantpl=str_replace("{ykt:FileName_{$i}}",$rowlist[$i],$mobantpl);
	}
}
$Save_url="sys_update_save.php?MenuID={$MenuID}&id={$rowlist[0]}";  //提交的页面


$vpattern= '/{#Class:(dropdownlist|radio|checkbox){1}:([0-9]+):(\w+)#}/i';
preg_match_all($vpattern,$mobantpl,$SArr);
//print_r($SArr);]
if(is_array($SArr)){
	for($j=0;$j<count($SArr[0]);$j++){
		if($SArr[1][$j]!=""){
			$d_Type=$SArr[1][$j];
			$d_ClassID=$SArr[2][$j];
			$d_FieldName=$SArr[3][$j];
			//读数据
			if($d_Type=="dropdownlist"){
				$optionitem="";
				$MenuIDFieldID=$System->GetFormConfigMenuIDFieldID($d_ClassID);  //获取MenuID所在字段序号
				$result=$db->query("select * from classsys where classsys{$MenuIDFieldID}={$d_ClassID}");
				$DatalistArr=$db->GetDatalist($result);
				$optionitem=$From->listboxsub($DatalistArr,0,0);
				$mobantpl=str_replace("{#Class:{$d_Type}:{$d_ClassID}:{$d_FieldName}#}",$optionitem,$mobantpl);
			}elseif($d_Type=="radio"){
				$radioitem="";
				$MenuIDFieldID=$System->GetFormConfigMenuIDFieldID($d_ClassID);  //获取MenuID所在字段序号
				$result=$db->query("select * from classsys where classsys{$MenuIDFieldID}={$d_ClassID}");
				while($row=$db->getarray($result)){
					$radioitem.="<input name=\"".$d_FieldName."\" type=\"radio\" value=\"".$row[0]."\">".$row[1]."</input>";
				}
				$mobantpl=str_replace("{#Class:{$d_Type}:{$d_ClassID}:{$d_FieldName}#}",$radioitem,$mobantpl);
			}elseif($d_Type=="checkbox"){
				$checkboxitem="";
				$MenuIDFieldID=$System->GetFormConfigMenuIDFieldID($d_ClassID);  //获取MenuID所在字段序号
				$result=$db->query("select * from classsys where classsys{$MenuIDFieldID}={$d_ClassID}");
				while($row=$db->getarray($result)){
					$checkboxitem.="<input name=\"".$d_FieldName."[]\" type=\"checkbox\" value=\"".$row[0]."\">".$row[1]."</input>";
				}
				$mobantpl=str_replace("{#Class:{$d_Type}:{$d_ClassID}:{$d_FieldName}#}",$checkboxitem,$mobantpl);	
			}
		}
	}
}



$mobantpl=str_replace("{ykt:Save_url}",$Save_url,$mobantpl);
$mobantpl=strtr($mobantpl,array('{ykt:gotourl}'=>$_SERVER['HTTP_REFERER']));
echo $mobantpl;
$html->includeend();
?>